package com.onpositive.wiki3.db.impl;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashSet;

import com.onpositive.wiki3.db.catmodel.Categories;
import com.onpositive.wiki3.db.catmodel.Category;
import com.onpositive.wiki3.db.catmodel.matches.classify.RelationConstants;
import com.onpositive.wiki3.db.catmodel.matches.classify.RelationStore;

public class Test9 {

	public static void main(String[] args) {
		final WikiDBImpl wikiDBImpl = new WikiDBImpl("C:/work/content");
		try {
			RelationStore ss = new RelationStore(wikiDBImpl);
			System.setProperty("wordnet.database.dir", "C:/work/wn/dict");
			final Categories c = new Categories(wikiDBImpl, new File(
					"C:/work/content/relation.dat"), true);
			// CategoryAccessImpl mm = (CategoryAccessImpl) wikiDBImpl
			// .getCategoryAccessor();
			DataInputStream ss1 = new DataInputStream(new BufferedInputStream(
					new FileInputStream(wikiDBImpl.getPath()
							+ "/props/props.dt")));
			Categories categories = ss.get(RelationConstants.IS_A);
			DataOutputStream rrr = new DataOutputStream(
					new BufferedOutputStream(new FileOutputStream(wikiDBImpl
							.getPath() + "/relations/props.dt")));
			HashSet<String> names = new HashSet<String>();
			names.add("date");
			try {
				int zq = 0;
				while (true) {
					String propName = ss1.readUTF();
					int readInt = ss1.readInt();
					String readUTF = ss1.readUTF();
					zq++;
					if (zq % 10000 == 0) {
						System.out.println(zq);
					}
					// System.out.println(readUTF);
					if (names.contains(propName)) {
						continue;
					}
					Category category = c.get(readInt);
					if (category == null) {
						continue;
					}
					int[] parents = category.getParents();
					for (int q : parents) {
						Category category2 = categories.get(q);
						if (category2 != null) {
							// System.out.println(category2);

							// System.out.println(propName);
							rrr.writeUTF(propName);
							rrr.writeInt(q);
						}
					}
				}
			} catch (EOFException e) {

			}
			rrr.close();

		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
}
